/**
 * @program: clms-second
 * @description: 角色控制层
 * @author: mitu_echo
 * @create: 2021-07-22 19:10
 **/

package com.second.system.controller;

import com.second.common.pojo.R;
import com.second.system.pojo.entity.Role;
import com.second.system.pojo.vo.ShowAllRoleVO;
import com.second.system.pojo.vo.ShowAllUserVO;
import com.second.system.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation("查询全部的角色")
    @RequestMapping("/showAllRole")
    public R showAllRole(ShowAllRoleVO showAllRoleVO) {

        System.out.println(showAllRoleVO);
        return roleService.showAllRole(showAllRoleVO);
    }

    @ApiOperation("查询用户拥有的角色")
    @RequestMapping("/showUserHasRole")
    public R showUserHasRole(Integer userid) {

        return roleService.showUserHasRole(userid);
    }

    @ApiOperation("修改用户拥有的角色")
    @RequestMapping("/updateUserHasRole")
    public R updateUserHasRole(@RequestParam("roleidList") List<Integer> roleidList,Integer userid) {

        return roleService.updateUserHasRole(roleidList,userid);
    }

    @ApiOperation("添加角色")
    @RequestMapping("/addRole")
    public R addRole(@RequestBody Role role) {

        return roleService.addRole(role);
    }

    @ApiOperation("修改角色")
    @RequestMapping("/updateRole")
    public R updateRole(@RequestBody Role role) {

        return roleService.updateRole(role);
    }

    @ApiOperation("删除角色")
    @RequestMapping("/delByRoleid")
    public R delByRoleid(Integer roleid) {

        return roleService.delByRoleid(roleid);
    }

    @ApiOperation("修改角色状态")
    @RequestMapping("/updateStatus")
    public R updateStatus(Integer roleid,Character status) {

        return roleService.updateStatus(roleid,status);
    }

    @ApiOperation("查询用户是否是管理员")
    @RequestMapping("isAdmin")
    public R isAdmin(Integer userid) {

        return roleService.isAdmin(userid);
    }
}
